home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
Internet Chooser
/
reggie
/
basic
/
stddebug.h
< prev
next >
Wrap
Text File
|
1996-06-22
|
6KB
|
148 lines
/* File "stddebug.h", Light Sockets - Copyright (C) Matt Slot, 1996 */
/* Standard debugging and error tracking macros. */
#ifndef __STD_DEBUG_HEADER__
#define __STD_DEBUG_HEADER__
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Functional Summary */
/*
Wrap function calls, default conditionals, and sanity-checks with the
following wrappers to provide error testing and reporting on MacOS and
ANSI platforms. Functions are divided into 4 categories:
ASSERT - Debugging-only utility used to sanity-checking pointers and
parameters that *should* always be valid, but for which you
have provided an external API to another developer. Debug
software will log a message and exit the program; non-debug
software should completely optimize the tests out.
TRACE - Simple logging utility for recording unusual circumstances
or soft errors which must be ignored. Tracing evaluates and
sets the "error" code, but does not stop or branch execution.
THROW - Error testing and logging facility for hard errors, which
force execution to branch. Require the presence of a CATCH
function toward the end.
CATCH - Zero-overhead function which acts as the target of execution
after a THROW event. Commands after a CATCH should dispose
structures while carefully testing for exceptional or error
cases.
By redefining _DEBUGFTN, it is possible to change the method by which errors
are reported. Be careful, however, because only certain report functions are
interrupt-safe. Finally, the _DEBUG #define differentiates between compiling
a debug version (much larger, slower) for internal or beta testing, and a
non-debug version for sending to end-users.
*/
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Include Files */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Preprocessor Defines */
#if defined(__MWERKS__)
#define PLATFORM_MAC
#endif
#define _DEBUG
#if defined(PLATFORM_MAC)
#define _DEBUGFTN _DebugMacsbug
#else
#define _DEBUGFTN _DebugPrintErr
#endif
#define _DEBUGSAFE ((_DEBUGFTN == _DebugMacsbug)|| (_DEBUGFTN == _DebugNotify))
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
#ifndef _DEBUG
#define qAssert() (0)
#define qAssertMsg(m) (0)
#define qAssertErr(e,m) (0)
#define qTrace() (0)
#define qTraceMsg(m) (0)
#define qTraceErr(e,m) (error = (e))
#define qThrow() { goto _CLEANUP; }
#define qThrowMsg(m) { goto _CLEANUP; }
#define qThrowErr(e,m) { (error = (e)); goto _CLEANUP; }
#else
/* Kludges to make the preprocessor convert __LINE__ into a string */
#define _mkstr(x) _mkval(x)
#define _mkval(x) #x
#define _FL __FILE__
#define _LN _mkstr(__LINE__)
#define qAssert() { _DEBUGFTN(0,0,_FL,_LN,0,1); }
#define qAssertMsg(m) { _DEBUGFTN((m),0,_FL,_LN,0,1); }
#define qAssertErr(e,m) { _DEBUGFTN((m),error=(e),_FL,_LN,0,1); }
#define qTrace() { _DEBUGFTN(0,0,_FL,_LN,0,0); }
#define qTraceMsg(m) { _DEBUGFTN((m),0,_FL,_LN,0,0); }
#define qTraceErr(e,m) { _DEBUGFTN((m),error=(e),_FL,_LN,0,0); }
#define qThrow() { _DEBUGFTN(0,0,_FL,_LN,1,0); goto _CLEANUP; }
#define qThrowMsg(m) { _DEBUGFTN((m),0,_FL,_LN,1,0); goto _CLEANUP; }
#define qThrowErr(e,m) { _DEBUGFTN((m),error=(e),_FL,_LN,1,0); \
goto _CLEANUP; }
#endif /* _DEBUG */
#define qAssertIfError(e,m) { long _e; if (_e=(e)) qAssertErr(_e,(m));}
#define qAssertIfNull(x,e,m) { if (!(x)) qAssertErr((e),(m)); }
#define qAssertIfFalse(x,e,m) { if (!(x)) qAssertErr((e),(m)); }
#define qAssertIfTrue(x,e,m) { if (x) qAssertErr((e),(m)); }
#define qTraceIfError(e,m) { long _e; if (_e=(e)) qTraceErr(_e,(m)); }
#define qTraceIfNull(x,e,m) { if (!(x)) qTraceErr((e),(m)); }
#define qTraceIfFalse(x,e,m) { if (!(x)) qTraceErr((e),(m)); }
#define qTraceIfTrue(x,e,m) { if (x) qTraceErr((e),(m)); }
#define qThrowIfError(e,m) { long _e; if (_e=(e)) qThrowErr(_e,(m)); }
#define qThrowIfNull(x,e,m) { if (!(x)) qThrowErr((e),(m)); }
#define qThrowIfFalse(x,e,m) { if (!(x)) qThrowErr((e),(m)); }
#define qThrowIfTrue(x,e,m) { if (x) qThrowErr((e),(m)); }
#define qCatch() { _CLEANUP: ; }
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Structure/Class Declarations */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Function Prototypes */
#ifdef __cplusplus
extern "C" {
#endif
void _DebugPrintErr(char *, long, char *, char *, int, int);
void _DebugPrintLog(char *, long, char *, char *, int, int);
#if defined(PLATFORM_MAC)
void _DebugMacsbug(char *, long, char *, char *, int, int);
void _DebugNotify(char *, long, char *, char *, int, int);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __STD_DEBUG_HEADER__ */